package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IContentService;
import com.mall.shopping.IHomeService;
import com.mall.shopping.IProductCateService;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.shopping.dto.NavListResponse;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @DATE: 28/9/2021  21:12
 * @USER: xiaom
 * @Author: 2232683886@qq.com
 * @Description: 商品模块
 */
@RestController
@RequestMapping("shopping")
public class ShoppingController {

    @Reference(timeout = 6000,retries = 3, check = false)
    IHomeService homeService;

    @Reference(timeout = 6000,retries = 3, check = false)
    IContentService contentService;

    @Reference(timeout = 6000,retries = 3, check = false)
    IProductCateService productCateService;

    /**
     * 显示主页
     * @return ResponseData
     */
    @Anoymous
    @GetMapping("homepage")
    public ResponseData homepage() {

        HomePageResponse response = homeService.homepage();

        if (response.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())) {
           return new ResponseUtil().setData(response.getPanelContentItemDtos());

        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

    /**
     * 显示导航栏
     * @return ResponseData
     */
    @Anoymous
    @GetMapping("navigation")
    public ResponseData navigation() {

        NavListResponse response = contentService.queryNavList();

        if (response.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response.getPannelContentDtos());

        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

    @Anoymous
    @GetMapping("categories")
    public ResponseData categories() {

        AllProductCateRequest request = new AllProductCateRequest();
        request.setSort("asc");

        AllProductCateResponse response = productCateService.getAllProductCate(request);

        if (response.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response.getProductCateDtoList());

        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }


}
